package cn.outsourcing.supermarket.controller.backstage;

import cn.outsourcing.supermarket.common.CommonPage;
import cn.outsourcing.supermarket.common.Result;
import cn.outsourcing.supermarket.common.constants.BackstageGoodsConstants;
import cn.outsourcing.supermarket.common.utils.ResultUtils;
import cn.outsourcing.supermarket.dto.backstage.BackstageGoodsDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageOrdersInfoDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageShopCartDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageUserListDTO;
import cn.outsourcing.supermarket.service.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 后台管理主页控制器
 *
 * @author gzkemays
 * @since 2021/10/25 16:37
 */
@RestController
@RequestMapping("/admin")
public class HomepageController {
  @Resource BackstageHomeService backstageHomeService;
  @Resource BackstageOrderService backstageOrderService;
  @Resource BackstageGoodsService backstageGoodsService;
  @Resource BackstageCategoryService backstageCategoryService;
  @Resource BackstageSpecificationService backstageSpecificationService;
  @Resource HiolabsAdminService adminService;
  @Resource HiolabsAdService adService;
  @Resource HiolabsNoticeService noticeService;

  @GetMapping("/index")
  public Result getStoreInfo() {
    return ResultUtils.simpleResult(backstageHomeService.getBaseData());
  }

  @GetMapping("/order")
  public Result getMain(BackstageOrdersInfoDTO dto) {
    return ResultUtils.pageResult(backstageOrderService.getOrdersInfo(dto));
  }

  @GetMapping("/goods")
  public Result getGoodsList(BackstageGoodsDTO dto) {
    return ResultUtils.pageResult(
        backstageGoodsService.getGoods(
            dto, BackstageGoodsConstants.ALL_GOODS, BackstageGoodsConstants.SORT_DEFAULT));
  }

  @GetMapping("/category")
  public Result getCategory() {
    return ResultUtils.simpleResult(backstageCategoryService.getCategory());
  }

  @GetMapping("/specification")
  public Result getSpecification() {
    return ResultUtils.simpleResult(backstageSpecificationService.getSpecification());
  }

  @GetMapping("/shopcart")
  public Result getShopCart(BackstageShopCartDTO dto) {
    return ResultUtils.simpleResult(backstageHomeService.getCartShop(dto));
  }

  @GetMapping("/user")
  public Result user(BackstageUserListDTO dto) {
    return ResultUtils.simpleResult(backstageHomeService.getUserList(dto));
  }

  @GetMapping("/ad")
  public Result ad(CommonPage page) {
    return ResultUtils.pageResult(adService.getAdListPageList(page));
  }

  @GetMapping("/notice")
  public Result notice() {
    return ResultUtils.simpleResult(noticeService.getAllNotice());
  }

  @GetMapping("/admin")
  public Result getAdmin() {
    return ResultUtils.simpleResult(adminService.getAdminList());
  }
}
